<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>云校通-教师-晚修辅导登记</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart style="background:#fff;" class="js-jf">
	<div class="weui_tab tab-bottom">
      	<div class="weui-header bg-blue">
	  		<div class="weui-header-left"> <a onclick="back()" href="javascript:" class="icon icon-109 f-white">返回</a> </div>
	    	<h1 class="weui-header-title">辅导统计</h1>
		</div>
		<div class="weui_tab_bd">
			<div class="weui_cells weui_cells_access ltbg-content borderLeft afterNone afterNoneBefore" style="margin-top:0;">
				<div class="rili calendar" id="calendar">
					
				</div>
			</div>
			<div class="weui_cells bd-t0 mt5 mb40">
		        <div class="weui_cell lblue bd-t0"> 
		            <div class="weui_cell_bd weui_cell_primary">
		                <p class=""><span id="totalDesc"></span>辅导统计</p>
		            </div>
		        </div>
		        <div class="weui_cell bd-t0" style="padding:0;" id="reportResult">
		        
		        </div>
		     </div>
		</div>
		<script id="report-table-template" type="text/x-handlebars-template">
			<table class="weui-table weui-border-tb">
              	<thead>
                <tr>
	                <th>姓名</th>
	                <th>是否<br/>班主任</th>
	                <th>周一<br/>(次)</th>
	                <th>周二<br/>(次)</th>
	                <th>周三<br/>(次)</th>
	                <th>周四<br/>(次)</th>
	                <th>八节<br/>(次)</th>
	                <th>总数<br/>(次)</th>
                </tr>
               </thead>
               <tbody>
               	{{#each list}}
               	<tr>
               		<td>{{teacherName}}</td>
               		<td>{{#if isClassTeacher}}是{{else}}否{{/if}}</td>
               		<td>{{d1Count}}</td>
               		<td>{{d2Count}}</td>
               		<td>{{d3Count}}</td>
               		<td>{{d4Count}}</td>
               		<td>{{d8Count}}</td>
               		<td>{{totalCount}}</td>
               	 </tr>
               	 {{/each}}
				</tbody>
			</table>
		</script>
    </div>
</body>
<script src="<%=basePath %>/js/calendar-xtbg.js"></script>
<script type="text/javascript">
	$(function() {
		window.dateObj = (function(){
		    var _date = new Date();    // 默认为当前系统时间
		    return {
		      getDate : function(){
		        return _date;
		      },
		      setDate : function(date) {
		        _date = date;
		      }
		    };
		})();
		
		// 设置calendar div中的html部分
		renderHtml();
		// 表格中显示日期
		showCalendarData();
		// 绑定事件
		bindEvent();
		
		$(".backNow").click(function(){
			dateObj.setDate(new Date());
  				showCalendarData();
		})	
		$("#calendar").on("click",".currentMonth",function(){
			var obj = $(this);
			var str = obj.attr("data");
			var thisData = str.substr(0,4) + "/" + str.substr(4,2) + "/" + str.substr(6,2);
			$("#calendar").find("td").removeClass("currentDay");
			obj.addClass("currentDay");
			getRegTotalList(1, new Date(thisData));
		})
		$("#calendar").on("click",".calMonth,.backNow",function(){
			var obj = $(this);
			var title = obj.closest(".calendar-title-box").find("#calendarTitle").html();
			title = title.replace(/[\u4e00-\u9fa5]/g, "-");
			getRegTotalList(2, new Date(title.substring(0, title.length-1)));
		})
		getRegTotalList(1, new Date());
	})
	function getRegTotalList(type, currDate) {
		var param = {totalType: type};
		if(type == 1) {
			var day = currDate.getDay() == 0 ? 7 : currDate.getDay();
			param.startDate = getTime(addDay(currDate, 1-day),'yyyy-MM-dd');
			param.endDate = getTime(addDay(currDate, 7-day),'yyyy-MM-dd');
			var getDate=getMonthWeek(currDate.getFullYear(), currDate.getMonth() + 1, currDate.getDate());
			$("#totalDesc").html(getDate.getYear + "年"+ getDate.getMonth + "月的第" + getDate.getWeek + "周("+param.startDate+"/" + param.endDate+")");
		}else {
			param.monthDate = getTime(currDate, 'yyyy-MM');
			$("#totalDesc").html(currDate.getFullYear() + "年" + (currDate.getMonth() + 1) + "月");
		}
		$.ajax({
    		url: basePath + "/ls/late/coach/getRegTotalList",
    		type: 'POST',
    		dataType : "json",
    		data: param,
    		success: function(rspData) {
    			var data = {list: rspData};
    			loadReportHtml(data);
    		},
    		error: function(data) {
    			$.alert("系统异常,请联系管理员", "");
    		}
    	});
	}
	function loadReportHtml(report) {
		var myTemplate = Handlebars.compile($("#report-table-template").html());
		Handlebars.registerHelper("equal", function(v1,v2,options) {
    		if(v1 == v2) {
    			//满足添加继续执行
    			return options.fn(this);
    		}else {
    			//不满足条件执行{{else}}部分
    			return options.inverse(this);
    		}
    	});
		$('#reportResult').html(myTemplate(report));
	}
</script>
</html>